{extend name="admin@public/base" /}
{block name="main-content"}
<link href="__PUBLIC__/jquery-ui/jquery-ui.min.css" media="all" rel="stylesheet" type="text/css" />
<div class="page-content">
    <div class="row maintop">
        <div class="col-xs-2 col-sm-2  margintop5">
            <a href="{:url('admin/organize/organizeAdd')}">
                <button class="btn btn-sm btn-danger">
                    <i class="ace-icon glyphicon glyphicon-plus bigger-110"></i>
                    添加
                </button>
            </a>
        </div>
      
        <form class="form-search form-horizontal" id="list-filter" method="post" action="{:url('admin/organize/index')}">
                <input type="hidden" name="org_type" value ="{$org_type}"/>
                <div class="col-xs-12 col-sm-1  margintop5">
                    <div class="input-group">
                        <select name="isvalid" class="ajax_change">
                            <option value="">状态</option>
                            <option value="1"<?php if($isvalid==='1'){ ?> selected <?php } ?>>有效</option>
                            <option value="0" <?php if($isvalid==='0'){ ?> selected <?php } ?>>禁用</option>
                        </select>
                    </div>
                </div>
                <div class="col-xs-8 col-sm-4   btn-sespan">
                    <div class="input-group">

                        <span class="input-group-addon">
                            <i class="ace-icon fa fa-check"></i>
                        </span>
                        <input type="text" name="name" id="name" class="form-control search-query admin_sea" value="" placeholder="输入需查询的公司名" />
                        <span class="input-group-btn">
                            <input type="hidden" value="" id="company_id" name="company_id"/>
                            <button type="submit" class="btn btn-purple btn-xs ajax-search-form">
                                <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                搜索
                            </button>
                        </span>
                    </div>
                </div>
            </form>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <div>
                <ul class="nav nav-tabs">
                    <li class="{eq name='$org_type' value='1'}active{/eq}"><a href="{:url('Organize/index',array('org_type'=>1))}">总店</a></li>
                    <li class="{eq name='$org_type' value='2'}active{/eq}"><a href="{:url('Organize/index',array('org_type'=>2))}">加盟商</a></li>
                </ul>
                <table class="table table-striped table-bordered table-hover" id="dynamic-table">
                    <thead>
                        <tr>
                            <th width="5%" class="center">编号</th>
                            <th width="" class="center">单位</th>
                            <th width="8%" class="center">业务类型</th>
                            <th width="7%" class="center">法人代表</th>
                            <th width="5%" class="center">状态</th>
                            <th width="10%" class="center">注册资本</th>
                            <th width="10%" class="center">社会统一编码</th>
                            <th width="8%" class="center">创建时间</th>
                            <th class="center" width="10%" style="border-right:#CCC solid 1px;">操作</th>
                        </tr>
                    </thead>

                    <tbody id="ajax-data">
                        {include file="organize/ajax_org_list"/}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- 显示模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form class="form-horizontal ajaxForm" name="member_group_runadd" method="post" action="{:url('admin/Organize/setAccountSubmit')}">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        账户信息
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-12">

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 用户名：  </label>
                                <div class="col-sm-10">
                                    <input type="text" name="user_name" id="user_name" placeholder="5位及以上数字英文字母组合" class="col-xs-10 col-sm-5" required/>
                                    <span class="lbl">

                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 密码：  </label>
                                <div class="col-sm-10">
                                    <input type="password" name="password" id="password" value="" placeholder="密码" class="col-xs-10 col-sm-5" required/>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>6位及以上数字英文字母组合</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" value="0" id="br_id" name="br_id"/>
                    <input type="hidden" value="0" id="org_id" name="org_id"/>
                    <button type="submit" class="btn btn-primary model_submit" >
                        提交保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </form>
</div><!-- /.modal -->
{/block}
{block name="scripts"}
<script src="__PUBLIC__/jquery-ui/jquery-ui.min.js"></script>
<script>

    $("#name").autocomplete({
        //source: availableTags
        minLength: 1,
        mustMatch: true,
        source: function(request, response)
        {
            var name = request.term;
            request.org_type = {$org_type};
            //console.log(request);
            $.getJSON("{:url('admin/Organize/ajaxGetCompanyInfoByName')}", request, function(data, status, xhr)
            {
                console.log(data);
                response(JSON.parse(data));
            });
        },
        select: function(event, ui)
        {
            if (ui.item.id > 0)
            {
                $(this).val(ui.item.name);
                $('#company_id').val(ui.item.id);
            }
            else
            {
                $(this).val("");
                $('#company_id').val(0);
            }
            return false;
        },
        focus: function() {
            return false;
        }
    }).data("ui-autocomplete")._renderItem = function(ul, item)
    {
        if (item.id > 0)
        {
            var show_text = "<a>[<font style='color:red;'>" + item.name + "</font>]</a>";
        }
        else
        {
            var show_text = "<a>" + item.name + "</a>";
        }
        return $("<li>").append(show_text).appendTo(ul);
    };
    $("#name").blur(function() {
        if ($(this).val() == "") {
            $('#company_id').val("");
        }
    });
    $(document).on("click", ".account", function() {
        var id = $(this).data("id");
        $.get("{:url('admin/Organize/setAcount')}", {id: id},
        function(data) {
            if (data == 0) {
                $("#user_name").val("kfs" + "000"+id);
                $("#password").val("admin123");
                $("#br_id").val(0);
            } else {
                $("#br_id").val(data.id);
                $("#user_name").val(data.user_name);
                $("#password").val(data.password);
            }
            $("#org_id").val(id);
        },'json');
    });

    $(document).on("click", ".model_submit", function() {
        if ($("#user_name").val().length < 5) {
            layer.alert("用户名不少于五位");
            return false;
        }
        if ($("#password").val().length < 6) {
            layer.alert("密码不少于六位");
            return false;
        }
        var a = $("#user_name").val();
        var b = $("#password").val();
        var c = /^([a-zA-Z])+$/;
        var d = /^\d+$/;
        if (c.test(a) || d.test(a)) {
            layer.alert("用户名必须由数字和字母组成");
            return false;
        }
        if (c.test(b) || d.test(b)) {
            layer.alert("密码必须由数字和字母组成");
            return false;
        }
    });

</script>
{/block}